iT邦幫忙

2025 iThome 鐵人賽

DAY 2
0

今天先來拿金鑰
我用的是Gemini API KEY
先到https://aistudio.google.com/apikey
點下Create API KEY,然後選擇 Gemini API
https://ithelp.ithome.com.tw/upload/images/20250916/20177921rmSzZOzd6x.png
在按下Create就可以拿到了,我的金鑰被我塗黑了(龜狗笑
https://ithelp.ithome.com.tw/upload/images/20250916/20177921P1cCRBDH0I.png

底下是簡單測試

import google.generativeai as genai

# 設定 API 金鑰
genai.configure(api_key="你的金鑰")

# 使用 Gemini 2.5 flash 模型
model = genai.GenerativeModel(model_name="models/gemini-2.5-flash")

# 發送問題
response = model.generate_content("你好嗎?")

# 輸出回答
print(response.text)

結果
https://ithelp.ithome.com.tw/upload/images/20250916/20177921K0KuGR19Mw.png


上一篇
DAY 1
下一篇
DAY 3
系列文
我的 AI 助手開發3
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言